import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store'
// import Index from "@/views/Index";
// import Test from "@/views/Test";
// import Home from "@/views/home/Home";
// import Archives from "@/views/archives/Archives";
// import Blog from "@/views/blog/Blog";
// import Tag from "@/views/tag/Tag";
// import Category from "@/views/category/Category";
// import Moments from "@/views/moments/Moments";
// import Friends from "@/views/friends/Friends";
// import About from "@/views/about/About";
// import Login from "@/views/Login";


Vue.use(VueRouter)

const routes = [
	{
		path: '/login',
		component:() => import("@/views/Login") ,
		meta: {
			title: '登录'
		}
	},	
	// {
	// 	path: '/test',
	// 	component: Test,
	// 	meta: {
	// 		title: '测试'
	// 	}
	// },
	{
		path: '/',
		component: () => import("@/views/Index"),
		redirect: '/home',
		children: [
			{
				path: '/home',
				name: 'home',
				component: () => import("@/views/home/Home"),
				meta: {
					title: '首页',

				}
			},
			{
				path: '/archives',
				name: 'archives',
				component: () => import("@/views/archives/Archives"),
				meta: {
					title: '日志',
				}
			},
			{
				path: '/blog/:id',
				name: 'blog',
				component: () => import("@/views/blog/Blog"),
				meta: {
					title: '博客'
				}
			},
			{
				path: '/tag/:name',
				name: 'tag',
				component: () => import("@/views/tag/Tag"),
				meta: {
					title: '标签',
				}
			},
			{
				path: '/category/:name',
				name: 'category',
				component: () => import("@/views/category/Category"),
				meta: {
					title: '分类',
				}
			},
			{
				path: '/moments',
				name: 'moments',
				component: () => import("@/views/moments/Moments"),
				meta: {
					title: '动态'
				}
			},
			{
				path: '/friends',
				name: 'friends',
				component: () => import("@/views/friends/Friends"),
				meta: {
					title: '资源分享'
				}
			},
			{
				path: '/about',
				name: 'about',
				component: () => import("@/views/about/About"),
				meta: {
					title: '关于我'
				}
			}
		]
	}
]
const scrollBehavior = function (to, from, savedPosition) {
            return to.meta
        }
const router = new VueRouter({
	mode: 'history',
	base: process.env.BASE_URL,
	routes,
	scrollBehavior,

})

//挂载路由守卫
router.beforeEach((to, from, next) => {
	document.documentElement.scrollTop = 0
	if (to.meta.title) {
		if (store.state.siteInfo.webTitleSuffix) {
			document.title = to.meta.title + store.state.siteInfo.webTitleSuffix
		} else {
			document.title = to.meta.title
		}
	}

	next()
})

export default router
